import TableLyout from "@/components/commonPublic/tableLyout.vue";
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"; //面包屑
import publicForm from "@/components/materialDataManage/fromCom.vue"; //模糊查询
import tree from "@/components/PhysicalQualityPage/rebarThicknessManage/el-tree"; //左侧机构树
import TableData from "@/components/public/el-table-pagination"; //主页面列表
import CustomDialog from "@/components/PhysicalQualityPage/rebarThicknessManage/rebarDetectionTask/index.vue";
import CustomDialog1 from "@/components/PhysicalQualityPage/rebarThicknessManage/rebarDetectionData/index.vue";

import formJs from "./regexDetail.js"; //新增弹框配置项

import {
    getUserCompanyTreeList, //左侧机构树接口
    getSteelProtectionTestTaskDataLists, //主页面列表接口
} from "@/api/request.js";
// import { statusType2 } from "@/utils/config"; //配置项
export default {
    name: "rebarRecordApproval",
    components: {
        TableLyout,
        elBreadcrumb, //面包屑
        publicForm, //模糊查询
        tree, //左侧组织机构数
        TableData, //主页面列表
        CustomDialog, //详情弹框
        CustomDialog1,//大表
    },
    data() {
        return {
            name: "rebarRecordApproval", //按钮配置页面代号
            queryCriteriaData: {}, //分页
            btnObj: [], //按钮
            searchObj: formJs.searchObj, //搜索条件
            dataFid: null,
            // 列表
            table_config: formJs.table_config,
            tableData: [], //列表数据列表
            // checked: true, //查看下级按钮
            loading: false, //列表数据加载loading
            getList: {
                fCompanyid: "", // 左侧选中组织机构id
                modelType: "2", // 0待办 1已办 2查询
                userId: "", // 查询待办或已办时传 列表页查询不传
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                page: 1, // 当前页码
                pageSize: 20, // 每页显示条数
                keyWord: "",
                keyType: "",
                timeDates: [],
            }, // 列表给后端传参
            // 列表

            // 弹框
            currentRow: null, //列表详情
            dialogTitle: "",
            isShow: false, //详情--是否显示弹框
            statusNum: null, //详情--点击那个按钮
            isShow1: false, //记录表--是否显示弹框
            statusNum1: null, //记录表--点击那个按钮
            typeDataShow: "",//记录表--展示那个
            isShow2: false, //示意图--是否显示弹框
            statusNum2: null, //示意图--点击那个按钮
            // 弹框


            // 左侧机构树
            treelength: false, //左侧树显示隐藏
            showName: "未选择公司",
            treeData: [], //左侧树状图数据
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            checkData: [],
            treeText: {
                companyId: null,
                text: null,
                userId: null,
            },
            // 左侧机构树

            // 下拉框树
            selectTreeData: [],
            selectCheckData: [],
            selectDefaultProps: {
                children: "children",
                label: "fSampletypename",
            },
            // 下拉框树
            userInfo: {}, //登录用户
        };
    },

    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));

        if (JSON.parse(sessionStorage.getItem("yjSmart-rebarThicknessManage_treeCheck"))) {
            var id = JSON.parse(
                sessionStorage.getItem("yjSmart-rebarThicknessManage_treeCheck")
            );
            this.checkData = [id.fCompanyid];
        }
        this.getDate();
        this.getTree();
        this.btnRole(this.name);

        this.table_config.operation.cols = [
            {
                prop: "fStatus",
                type: "primary",
                handleRow: this.handleRow,
            },
        ];
        this.table_config.operation["specialClass"] = function (rowData) {
            var color = null;
            if (rowData == "待检测") {
                color = "red !important";
            } else if (rowData == "检测中") {
                color = "orange !important";
            } else if (rowData == "已完成") {
                color = "green !important";
            } else {
                color = "#409eff !important";
            }
            return color;
        };

    },
    methods: {
        btnRole(name) {
            if (this.userInfo.userId != "System") {
                var btnList = [];
                var ModuleList = JSON.parse(
                    sessionStorage.getItem("yjSmart-ModuleList")
                );
                if (ModuleList.length > 0) {
                    ModuleList.map((item) => {
                        if (item.fEncode == name) {
                            btnList = item.modulebuttonList;
                        }
                    });
                    btnList.map((item) => {
                        item["disabled"] = false;
                    });
                    this.btnObj = btnList;
                }
            } else {
                this.btnObj = formJs.btnObj;
            }
        },
        getBtnName(name, status) {
            this.yj_edit(status);
        },

        yj_edit(num) {
            if (num == 7) { //查看
                if (this.dataFid != null) {
                    this.statusNum = 7
                    this.isShow1 = true;

                } else {
                    this.$message.warning("请先选择需要查看的数据");

                }
            }

        },
        // 左侧树结构
        getTree() {
            this.treeText = {
                companyId: this.userInfo.companyId,
                userId: this.userInfo.userId,
                // text: "4", // 0其他  1 砼拌合站 2水稳 3沥青
            };
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);
                        if (this.treeData[0].children == undefined) {
                            this.treelength = false; //左侧组织机构是否显示
                        } else {
                            this.treelength = true;
                        }

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(
                                sessionStorage.getItem("yjSmart-rebarThicknessManage_treeCheck")
                            ).fShortname;

                            this.getList.companyId = this.checkData[0];
                        } else {
                            this.checkData[0] = this.treeData[0].fCompanyid;
                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
                        }
                        this.yj_searchForm(this.getList); // 调用主页面列表接口
                        // 列表
                    } else {
                        this.$message.error(res.msg);
                        // this.$message.error("获取组织机构失败");
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },
        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList.fCompanyid = data.fCompanyid;
            this.getList.page = 1;
            this.getList.pageSize = 20;
            this.yj_searchForm(this.getList);
        },
        // 获取列表数据
        yj_searchForm(data) {
            window.sessionStorage.setItem(
                "yjSmart-rebarThicknessManage_getLists",
                JSON.stringify(data)
            );
            var obj = {
                companyId: data.fCompanyid, //左侧选中组织机构id
                keyType: data.keyType,
                modelType: data.modelType, // 0待办 1已办 2查询
                page: data.page, // 当前页码
                pageSize: data.pageSize, // 每页显示条数
                userId: "", // 查询待办或已办时传 列表页查询不传
                startDates: data.startDates, // 开始时间
                endDates: data.endDates, // 截至时间
            };
            this.loading = true;
            var that = this;
            getSteelProtectionTestTaskDataLists(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.pageInfo.list;
                        this.queryCriteriaData = res.data.pageInfo;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    this.$message.error("列表数据 接口出错", error.msg);
                    this.loading = false;
                });
        },
        // 点击当前行
        rowChange(val) {
            this.dataFid = val.fId;
            this.currentRow = val;
            return val;
        },
        // 查看
        yj_viewForm(row, label) {
            this.currentRow = row;
            if (label == "报告编号") {
                this.statusNum1 = 7;
                this.dialogTitle = "钢保检测数据查看";
                this.isShow1 = true;
                this.typeDataShow = "1";
            }
            if (label == "记录编号") {
                this.statusNum1 = 7;
                this.dialogTitle = "钢保检测数据查看";
                this.isShow1 = true;
                this.typeDataShow = "0";
            }
            if (label == "任务编号") {
                this.statusNum = 7;
                this.dialogTitle = "任务编号查看";
                this.isShow = true;
            }
            if (label == "厚度与间距示意") {
                this.statusNum2 = 7;
                this.dialogTitle = "示意图查询";
                this.isShow2 = true;
                // this.statusNum1 = 7;
                // this.dialogTitle = "报告编号查看";
                // this.isShow1 = true;
            }
        },
        //获取时间
        getDate() {
            if (JSON.parse(sessionStorage.getItem("yjSmart-rebarThicknessManage_getLists"))) {
                var dataList = JSON.parse(
                    sessionStorage.getItem("yjSmart-rebarThicknessManage_getLists")
                );
                this.getList = {
                    fCompanyid: dataList.fCompanyid, // 左侧选中组织机构id
                    modelType: "2", // 0待办 1已办 2查询
                    userId: this.userInfo.userId, // 查询待办或已办时传 列表页查询不传
                    startDates: dataList.startDates, // 开始时间
                    endDates: dataList.endDates, // 截至时间
                    page: 1, // 当前页码
                    pageSize: 20, // 每页显示条数
                    keyWord: "",// 试验名称、报告编号、工程部位/用途：
                    keyType: "",// 检测类型
                    timeDates: [dataList.startDates, dataList.endDates],
                };
            } else {
                this.getList.startDates = this.common.getDay(-6); // 开始时间
                this.getList.endDates = this.common.getDay(0); // 截至时间
                this.getList.timeDates = [
                    this.getList.startDates,
                    this.getList.endDates,
                ];
            }
        },

        // 弹框组件
        refreshList() {
            //刷新列表
            this.$nextTick(() => {
                this.yj_searchForm(this.getList);
            });
        },
        closeDialog() {
            this.isShow = false;
            this.isShow1 = false;
        },
        // 弹框组件

        // 时间间隔
        selectTime(e) {
            if (e[0] != "" && e[1] != "") {
                this.getList.startDates = e[0] + " " + "00:00:00"; // 开始时间
                this.getList.endDates = e[1] + " " + "23:59:59"; // 截至时间
            } else {
                this.getList.startDates = ""; // 开始时间
                this.getList.endDates = ""; // 截至时间
            }
            this.getList.timeDates = [e[0], e[1]];
            this.yj_searchForm(this.getList);
        },
    },
};